/* 
 * File:   temperature.h
 * Author: apleilx
 */

#ifndef TEMPTASK_H_
#define	TEMPTASK_H_

#ifdef   _TEMPLIB_MODULE_
#define  TEMP_EXT
#else
#define  TEMP_EXT  extern
#endif

#include "stdint.h"

#ifdef	__cplusplus
extern "C" {
#endif

#define TEMP_CH_AMOUNT                  8                                           // temperature channel amount
    
#define TEMP_ERR_LIMITE_H_MASK          0x01
#define TEMP_ERR_LIMITE_L_MASK          0x10
#define TEMP_ERR_TABLE_H_MASK           0x02
#define TEMP_ERR_TABLE_L_MASK           0x20
    
#define TEMP_DIVISION_MAX               (20000L)
#define TEMP_DIVISION_MIN               (0L)
    
/*-----------------------------------------------------------------------------*
 * 
 * ADMarkH    -->     DivisionMax    
 * ADMarkL    -->     DivisionMin
 * 
 * Dx = (ADx - ADMarkL) * (DivisionMax - DivisionMin) / (ADMarkH -  ADMarkL)
 * Tx = (Dx - x0) * (y1 - y0) / (x1 - x0) 
 *-----------------------------------------------------------------------------*/    
    
    typedef struct
    {
        int16_t Division;
        int16_t Temp;
        
    } TEMP_TABLE_Type;
    
    typedef struct
    {
        int16_t MarkADL;
        int16_t MarkADH;
    } TEMP_AD_MARK_Type;
    
    typedef struct
    {
        int16_t MarkTempL;
        int16_t MarkTempH;
    } TEMP_VAL_MARK_Type;	
	
    typedef struct
    {
        int16_t PB;
        int16_t PK;
    } TEMP_CORRECT_Type;
    
    typedef struct
    {
        int16_t LimiteH;
        int16_t LimiteL;
    } TEMP_LIMITE_Type;
    
	TEMP_EXT uint8_t              TempErrSt[TEMP_CH_AMOUNT];
	TEMP_EXT int16_t              TempADVal[TEMP_CH_AMOUNT];
	TEMP_EXT float                Temperature[TEMP_CH_AMOUNT];
	TEMP_EXT float                TemperatureDisp[TEMP_CH_AMOUNT];
	
    TEMP_EXT TEMP_AD_MARK_Type     TempMarkTable[TEMP_CH_AMOUNT];
	TEMP_EXT TEMP_VAL_MARK_Type    TempValMarkTable[TEMP_CH_AMOUNT];
    TEMP_EXT TEMP_CORRECT_Type     TempCorrectTable[TEMP_CH_AMOUNT];
    TEMP_EXT TEMP_LIMITE_Type      TempLimiteTable[TEMP_CH_AMOUNT];
    TEMP_EXT const TEMP_TABLE_Type *TempSensorTab;                         
    
    void TempCal(uint8_t Ch);
    int16_t  TempGet(uint8_t Ch);
	int16_t  DispTempGet(uint8_t Ch);
    void TempADSet(uint8_t Ch ,int16_t AD_Val);
    uint8_t TempErrGet(uint8_t Ch);
	


#ifdef	__cplusplus
}
#endif

#undef TEMP_EXT

#endif	/* TASK_H */

